package com.ysx.oa.teacher.controller;
import com.ysx.oa.clazz.bean.ClazzBean;
import com.ysx.oa.clazz.bean.ClazzStudentTeacherBean;
import com.ysx.oa.clazz.service.ClazzService;
import com.ysx.oa.delay.bean.DelayBean;
import com.ysx.oa.role.bean.RoleBean;
import com.ysx.oa.teacher.bean.TeacherBean;
import com.ysx.oa.teacher.dto.MyDto;
import com.ysx.oa.teacher.service.TeacherService;
import com.ysx.oa.user.bean.UserBean;
import com.ysx.oa.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping("/teacher")
public class TeacherController {
    @Autowired
    private TeacherService teacherService;

    @Autowired
    private UserService userService;
    @Autowired
    private ClazzService clazzService;

    // http://localhost:8080/kaoqin/teacher/add?id=800200

    @RequestMapping(value="/findTeacherInforByClazzType",method = RequestMethod.GET)
    public Map<String,Object> findTeacherInforByClazzType(Integer type) {
        Map<String, Object> map = new HashMap();
        List<MyDto> teacherInfor = teacherService.findTeacherInforByClazzType(type);
        map.put("code", 200);
        map.put("message", "success");
        map.put("data",teacherInfor);
        return map;
    }


    @RequestMapping(value="/findAllClazz",method = RequestMethod.GET)
    public Map<String,Object> findAllClazz() {
        Map<String, Object> map = new HashMap();
        List<ClazzBean> clazzList = clazzService.findAllClazz();
        map.put("code", 200);
        map.put("message", "success");
        map.put("data",clazzList);
        return map;
    }
    /**
     * 方法描述:http://localhost:8080/kaoqin/teacher/add?
     * @author: 袁海华
     * @date: 2021/11/22 15:24
     * @param: [teacherController]
     * @return: java.util.Map<java.lang.String,java.lang.Object>
     */
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public Map<String,Object> add(@RequestBody TeacherBean teacherBean){
        Map<String,Object> map = new HashMap();
        teacherService.add(teacherBean);

        map.put("code",200);
        map.put("message","success");
        map.put("data",teacherBean);
        return map;
    }
    /**
     * 方法描述:http://localhost:8080/kaoqin/teacher/deleteById?
     * @author: 袁海华
     * @date: 2021/11/23 14:25
     * @param: [teacherId]
     * @return:
     */
    @RequestMapping(value = "/deleteById",method = RequestMethod.POST)
    public Map<String,Object> deleteById(@RequestBody   Map<String,Integer> teacherId){
        Map<String,Object> map = new HashMap();
        teacherService.deleteById(teacherId.get("teacherId"));

        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }
    /**
     * 方法描述:http://localhost:8080/kaoqin/teacher/updateById?
     * @author: 袁海华
     * @date: 2021/11/23 14:25
     * @param: [teacherBean]
     * @return:
     */
    @RequestMapping(value = "/updateById",method = RequestMethod.POST)
    public Map<String,Object> updateById(@RequestBody TeacherBean teacherBean){
        Map<String,Object> map = new HashMap();
        teacherService.updateById(teacherBean);
        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }
    /**
     * 方法描述:http://localhost:8080/kaoqin/teacher/updateTeacherInforByTeacherId?
     * @author: 袁海华
     * @date: 2021/11/23 14:25
     * @param: [userBean]
     * @return:
     */
    @RequestMapping(value = "/updateTeacherInforByTeacherId",method = RequestMethod.POST)
    public Map<String,Object> updateTeacherInforByTeacherId(@RequestBody UserBean userBean){
        Map<String,Object> map = new HashMap();
        teacherService.updateTeacherInforByTeacherId(userBean);
        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }
    /**
     * 方法描述:http://localhost:8080/kaoqin/teacher/findById?
     * @author: 袁海华
     * @date: 2021/11/23 14:25
     * @param: [teacherId]
     * @return:
     */
    @RequestMapping(value="/findById",method = RequestMethod.GET)
    public Map<String,Object> findById(Integer teacherId){
        Map<String,Object> map = new HashMap();
        TeacherBean teacherBean = teacherService.findById(teacherId);
        map.put("code",200);
        map.put("message","success");
        map.put("data",teacherBean);
        return map;
    }
    /**
     * 方法描述:http://localhost:8080/kaoqin/teacher/findLateStudentInforByTeacherId?
     * @author: 袁海华
     * @date: 2021/11/23 14:25
     * @param: [teacherId]
     * @return:
     */
    @RequestMapping(value="/findLateStudentInforByTeacherId",method = RequestMethod.GET)
    public Map<String,Object> findLateStudentInforByTeacherId(Integer teacherId) {
        Map<String, Object> map = new HashMap();
        List<DelayBean> delayBeanList = teacherService.findLateStudentInforByTeacherId(teacherId);
        map.put("code", 200);
        map.put("message", "success");
        map.put("data",delayBeanList);
        return map;
    }
    /**
     * 方法描述:http://localhost:8080/kaoqin/teacher/findStudentIdByTeacherId?
     * @author: 袁海华
     * @date: 2021/11/23 14:25
     * @param: [teacherId]
     * @return:
     */
    @RequestMapping(value="/findStudentIdByTeacherId",method = RequestMethod.GET)
    public Map<String,Object> findStudentIdByTeacherId(Integer teacherId) {
        Map<String, Object> map = new HashMap();
        List<Integer> studentIdList = teacherService.findStudentIdByTeacherId(teacherId);
        map.put("code", 200);
        map.put("message", "success");
        map.put("data",studentIdList);
        return map;
    }
    @RequestMapping(value="/findAllTeacherIdByRoleId",method = RequestMethod.GET)
    public Map<String,Object> findAllTeacherIdByRoleId(Integer roleId) {
        Map<String, Object> map = new HashMap();
        List<Integer> teacherIdList = teacherService.findAllTeacherIdByRoleId(roleId);
        map.put("code", 200);
        map.put("message", "success");
        map.put("data",teacherIdList);
        return map;
    }
    @RequestMapping(value = "/addClazzByTeacherId",method = RequestMethod.POST)
    public Map<String,Object> addClazzByTeacherId(@RequestBody ClazzStudentTeacherBean clazzStudentTeacherBean){
        Map<String,Object> map = new HashMap();
        teacherService.addClazzByTeacherId(clazzStudentTeacherBean);
        map.put("code",200);
        map.put("message","success");
        map.put("data",null);
        return map;
    }
    /**
     * 方法描述:根据ID查看老师的姓名,电话,id
     * @author: 袁海华
     * http://localhost:8080/kaoqin/teacher/findStudentOrTeacherByNotClass?id=20020
     * @date: 2021/11/25 12:17
     * @param: [roleBean]
     * @return:
     */
    @RequestMapping(value="/findStudentOrTeacherByNotClass",method = RequestMethod.GET)
    public Map<String,Object> findStudentOrTeacherByNotClass(RoleBean roleBean) {
        Map<String, Object> map = new HashMap();
        List<UserBean> teacherList = teacherService.findStudentOrTeacherByNotClass(roleBean);
        map.put("code", 200);
        map.put("message", "success");
        map.put("data",teacherList);
        return map;
    }


}
